﻿using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DianShangHouTai.Models
{
    /// <summary>
    /// 用户获取角色数据
    /// </summary>
    public class RoleService
    {
        ShopContext db = new ShopContext();
        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<Role> Role_User()
        {
            var s = db.Role.Select(p => new { p.Id, p.RoleName }).ToList();
            List<Role> roles = new List<Role>();
            foreach (var item in s)
            {
                roles.Add(new Role { Id = item.Id, RoleName = item.RoleName });
            }
            return roles;
        }
        /// <summary>
        /// 根据用户查询Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Role_User> User_Role_Searchs (int? id)
        {
            var res = db.Role_User.Select(p => new { p.UserId, p.RoleId }).Where(p => p.UserId == id).ToList();
            List<Role_User> list = new List<Role_User>();
            foreach (var item in res)
            {
                list.Add(new Role_User { RoleId = item.RoleId });
            }
            return list;
        }
        public static List<Message> Message(int shopid)
        {
            using (ShopContext db = new ShopContext())
            {

                string sql = string.Format(@"SELECT  dbo.Messages.LiuYanMsg, dbo.Messages.LiuYanRiQi, dbo.Customers.CustomerNiChengFROM      dbo.Customers INNER JOINdbo.Messages ON dbo.Customers.Id = dbo.Messages.Id", shopid);
                List<Message> Message = db.Database.SqlQuery<Message>(sql).ToList();

                return Message;
            }
        }
    }
}